<template>
  <!-- 我的代码是世界最好的代码 -->
  <div id="ap">
    <myh title="购物"></myh>
    <myt :list="list">
      <template #bb>
        <th>#</th>
        <th>商品名称</th>
        <th>价格</th>
        <th>标签</th>
        <th>操作</th>
      </template>
      <!-- 我的代码是世界上最好的代码 -->
      <template #sb="scope" v-if="is">
        <td>{{ scope.row.id }}</td>
        <td>{{ scope.row.goods_name }}</td>
        <td>{{ scope.row.goods_price }}</td>
        <td>
          <span
            class="badge bg-warning"
            style="margin-left: 5px"
            v-for="(item, index) in scope.row.tags"
            :key="index"
            >{{ item }}</span
          >
        </td>
        <td>
          <button @click="shanchu(scope.row.id)" class="btn btn-dager">
            删除
          </button>
        </td>
      </template></myt
    >
    <div @click="bianse">
      <button id="cc" class="pin" @click="is = !is">
        {{ is == true ? "收起" : "展开" }}
      </button>
    </div>
    <!-- 写作业很累回家要奖励自己了 -->
  </div>
</template>
       
   

<script>
import myh from "../components/myh.vue";
import myt from "../components/myt.vue";
export default {
  name: "ShangpingMyg",
  components: {
    myh,
    myt,
  },

  data() {
    return {
      list: [],
      is: true,
    };
  },

  mounted() {
    document.querySelector("#cc").style.backgroundColor = "red";
  },

  methods: {
    shanchu(id) {
      let index = this.list.findIndex((item) => item.id == id);
      this.list.splice(index, 1);
    },
    bianse() {
      if (this.is == false) {
        console.log(11);
        document.querySelector("#cc").style.backgroundColor = "green";
      } else {
        document.querySelector("#cc").style.backgroundColor = "red";
      }
    },
  },
  created() {
    this.$axios({
      method: "get",
      url: "/api/goods",
    }).then(({ data: res }) => {
      this.list = res.data;
      console.log(this.list);
    });
  },
};
</script>

<style lang="less" scoped>
#ap {
  padding-top: 45px;
  .pin {
    width: 100%;
    height: 50px;
    // background-color: red;
  }
}
</style>